#pragma once

#include <iostream>
#include <vector>

using namespace std;

class Polynomial
{
public:
    Polynomial();

    Polynomial operator+( const Polynomial& rhs ) const;
	Polynomial operator*( const double rhs ) const;
	Polynomial operator*( const Polynomial& rhs ) const;
    void print( ostream & out ) const;

	//TODO: add other operators -, /, derivative etc.

	// Get and Set functions
	void setCoefficient(size_t i, double val);
	double getCoefficient(size_t i) const {return (i < _coefficients.size()) ? _coefficients[i] : 0;};

	unsigned int degree() const { return _degree; };

	double evaluate(double x) const; // use Horner's method to evaluate the polynomial at x
	
protected:
	size_t _degree;
    vector<double> _coefficients;
    
};

inline ostream & operator<<( ostream & out, const Polynomial & rhs )
{
	rhs.print( out );
	return out;
}

